package com.ms.p2p.template.directive;

import com.alibaba.dubbo.config.annotation.Reference;
import com.google.common.collect.Lists;
import com.ms.common.utils.DirectiveUtils;
import com.ms.p2p.provider.LoanTenderRecordProvider;
import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import org.springframework.stereotype.Repository;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by xing_ on 2017/6/16.
 * 借款标的投资记录
 */
@Repository
public class LoanTenderListDirective extends BaseDirective {

    public static final String BORROW_ID = "borrowId";

    @Reference
    private LoanTenderRecordProvider loanTenderRecordProvider;

    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
        Integer borrowId = DirectiveUtils.getInt(BORROW_ID, params);
        List tenders = Lists.newArrayList();
        if(borrowId != null){
            tenders = loanTenderRecordProvider.getList(borrowId);
        }
        renderParamToBody(OUT_LIST, tenders, env, body);
    }
}
